<template>
  <div style="height: 100%; width: 100%; position: relative" ref="maindev">
      <div class="pagetop" ref="topdev">
          <table style="width: 100%; font-size: 12px" border="0">
              <tr>
                  <td colspan="10">
                      <table width="100%">
                          <tr>
                              <td align="right">
                                  <el-dropdown @command="handleCommand" style="font-size: 12px">
                                      <u class="el-dropdown-link">
                                          {{ datename }}
                                      </u>
                                      <el-dropdown-menu slot="dropdown">
                                          <el-dropdown-item command="签收日期">
                                              <font font-size="12px">签收日期</font>
                                          </el-dropdown-item>
                                          <el-dropdown-item command="退回日期">
                                              <font font-size="12px">退回日期</font>
                                          </el-dropdown-item>
                                      </el-dropdown-menu>
                                  </el-dropdown>
                              </td>
                              <td style="width: 265px">
                                  <el-date-picker v-model="datetime1" type="date" placeholder="开始日期" value-format="yyyy-MM-dd 00:00:00" size="mini" :clearable="false" style="width: 120px"></el-date-picker> 至
                                  <el-date-picker v-model="datetime2" type="date" placeholder="结束日期" value-format="yyyy-MM-dd 23:59:59" size="mini" :clearable="false" style="width: 120px"></el-date-picker>
                              </td>
                              <td colspan="2">
                                  <el-radio v-model="querytype" label="1" size="mini">退回原因</el-radio>
                                  <el-radio v-model="querytype" label="2" size="mini">原因归类</el-radio>
                              </td>
                              <td>
                                  <el-checkbox v-model="deptnoflag" true-label="1" false-label="0" @change="clearData()">科室</el-checkbox>
                                  <el-checkbox v-model="wardnoflag" true-label="1" false-label="0" @change="clearData()">病区</el-checkbox>
                                  <el-checkbox v-model="specimenflag" true-label="1" false-label="0" @change="clearData()">样本类型</el-checkbox>
                                  <el-checkbox v-model="labdetpflag" true-label="1" false-label="0" @change="clearData()">检验科室</el-checkbox>
                                  <el-checkbox v-model="pattypeflag" true-label="1" false-label="0" @change="clearData()">病人类型</el-checkbox>
                                  <el-checkbox v-model="labgroupflag" true-label="1" false-label="0" @change="clearData()">检验组别</el-checkbox>
                                  <el-checkbox v-model="reqgroupflag" true-label="1" false-label="0" @change="clearData()">分单类别</el-checkbox>
                                  <el-checkbox v-model="reqitemflag" true-label="1" false-label="0" @change="clearData()">申请项目</el-checkbox>
                                  <el-checkbox v-model="yearflag" true-label="1" false-label="0" @change="clearData()">年</el-checkbox>
                                  <el-checkbox v-model="monthflag" true-label="1" false-label="0" @change="clearData()">月</el-checkbox>
                                  <el-checkbox v-model="dayflag" true-label="1" false-label="0" @change="clearData()">
                                      日</el-checkbox>
                              </td>
                          </tr>
                      </table>
                  </td>
              </tr>
              <tr v-show="ShowElse">
                  <td align="right">病区</td>
                  <td>
                      <el-select v-model="wardno" @dblclick.native="popMultipleChk(wardno, 'wardno', wardOption, '病区选择')" filterable clearable style="width: 100%">
                          <el-option v-for="(item, index) in wardOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                      </el-select>
                  </td>
                  <td align="right">样本类型</td>
                  <td>
                      <el-select v-model="specimencode" @dblclick.native="popMultipleChk(specimencode, 'specimencode', specOption, '标本选择')" filterable clearable style="width: 100%">
                          <el-option v-for="(item, index) in specOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                      </el-select>
                  </td>
                  <td align="right">病人类型</td>
                  <td>
                      <el-select v-model="pattypecode" @dblclick.native="popMultipleChk(pattypecode, 'pattypecode', pattypeOption, '病人类型选择')" filterable clearable style="width: 100%">
                          <el-option v-for="(item, index) in pattypeOption" :value="item.data" :label="item.display" :key="index"></el-option>
                      </el-select>
                  </td>
                  <td align="right">科室</td>
                  <td>
                      <el-select v-model="reqdeptno" @dblclick.native="popMultipleChk(reqdeptno, 'reqdeptno', deptOption, '科室选择')" filterable clearable style="width: 100%">
                          <el-option v-for="(item, index) in deptOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                      </el-select>
                  </td>
                  <td align="right">执行科室</td>
                  <td>
                      <rm-ddl-common datatype="dept" dataname="科室" v-model="txtperformdept" width="100%" @change="performdeptChange">
                      </rm-ddl-common>
                  </td>

                  <!-- <td align="right">标本类型组合</td>
                  <td>
                      <rm-ddl-common datatype="seccode" kindno="workgroup" dataname="标本类型组合" v-model="workgroup" width="100%"></rm-ddl-common>
                  </td> -->
              </tr>
              <tr v-show="ShowElse">
                  <td align="right">检验科室</td>
                  <td>
                      <el-select v-model="labdeptcode" @dblclick.native="popMultipleChk(labdeptcode, 'labdeptcode', labdeptOption, '检验科室选择')" filterable clearable style="width: 100%">
                          <el-option v-for="(item, index) in labdeptOption" :key="index" :value="item.data" :label="item.display"> </el-option>
                      </el-select>
                  </td>
                  <td align="right">检验组别</td>
                  <td>
                      <el-select v-model="labgroupid" @dblclick.native="popMultipleChk(labgroupid, 'labgroupid', labgroupOption, '请选择检验组别')" filterable clearable style="width: 100%">
                          <el-option v-for="(item, index) in labgroupOption" :key="index" :value="item.data" :label="item.display"></el-option>
                      </el-select>
                  </td>
                  <td align="right">报告单元</td>
                  <td>
                      <el-select v-model="rptunitid" @dblclick.native="popMultipleChk(rptunitid, 'rptunitid', rptunitOption, '请选择报告单元')" filterable clearable style="width: 100%">
                          <el-option v-for="(item, index) in rptunitOption" :key="index" :value="item.data" :label="item.display"></el-option>
                      </el-select>
                  </td>
                  <td align="right">单元组合</td>
                  <td>
                      <rm-ddl-common datatype="labrptunitgroup" v-model="rptunitidcomb" dataname="单元组合" width="100%" :appendtobody="true" @change="rptunitcombChange"></rm-ddl-common>
                  </td>
                  <td align="right">分单类别</td>
                  <td>
                      <el-select v-model="reqgroupid" @dblclick.native="popMultipleChk(reqgroupid, 'reqgroupid', reqgroupOption, '请选择分单类别')" filterable clearable style="width: 100%">
                          <el-option v-for="(item, index) in reqgroupOption" :key="index" :value="item.data" :label="item.display"></el-option>
                      </el-select>
                  </td>
              </tr>
              <tr v-show="ShowElse">
                  <td></td>
                  <td colspan="9">
                      <el-checkbox v-model="allreqstat" true-label="1" false-label="0">包含作废条码</el-checkbox>
                      <el-checkbox v-model="noundivide" true-label="1" false-label="0">剔除退回原因未分类</el-checkbox>
                      <el-checkbox v-model="nounusedreq" true-label="1" false-label="0">剔除无效申请单</el-checkbox>
                      <el-checkbox v-model="showrate" true-label="1" false-label="0">显示百分比</el-checkbox>
                  </td>
              </tr>
              <tr>
                  <td colspan="13" align="right">
                      <!-- <label style="color: #c7c7c7; margin-right: 15px">数据来源：镜像统计库</label> -->
                      <el-link :underline="false" @click="btn_openselEvent">{{ ShowElse ? "收起▲" : "展开▼" }}</el-link>
                      <el-button @click.native="QueryData()" v-has="'PINQUERY'" type="primary" icon="el-icon-search">
                          查询</el-button>
                      <el-button @click.native="BtnExport" icon="el-icon-upload2">导出</el-button>
                      <!--<el-button @click.native="BtnSort" icon="el-icon-sort">排序</el-button>
                      <el-button @click.native="BtnClear" icon="el-icon-close">清除</el-button>-->

                      <!-- <el-button @click.native="BtnPrint" icon="el-icon-printer">打印</el-button> -->
                  </td>
              </tr>
          </table>
      </div>
      <div class="pagecenter" ref="centerdev">
          <vxe-table :data.sync="tableData" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" show-overflow ref="xTable1" :height="tableheight" :loading="loading" class="editable-footer" :footer-method="footerMethod" :footer-cell-class-name="footerCellClassName" border size="mini" show-header-overflow highlight-current-row highlight-hover-row show-footer resizable stripe @cell-dblclick="rCellDblClick" :cell-class-name="cellClassName">
              <vxe-table-column v-for="item in tableColumns" :field="item.field" :title="item.title" :key="item.field" :width="item.width" header-align="center" :align="item.align" sortable :formatter="formatFun">
              </vxe-table-column>
          </vxe-table>
      </div>

      <el-dialog width="900px" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :title="multichktitle" :visible.sync="dialogMultipleVisible" :destroy-on-close="true" v-if="dialogMultipleVisible">
          <rm-SqlMultiple :leftOption="option1" :rightOption="option2" :name="fieldname" @change="closedialog" ref="multidialog"></rm-SqlMultiple>
      </el-dialog>
      <el-dialog width="1100px" :title="dlgDetailTitle" v-el-drag-dialog :append-to-body="true" :close-on-click-modal="false" :visible.sync="dialogDetailVisible" :destroy-on-close="true">
          <div style="height: 30px;text-align:right;padding-right:10px;">
              <el-button @click="ExportResult()" icon="el-icon-download">导出</el-button>
          </div>
          <div style="height: 500px; width: 100%">
              <rm-layout-left splitcolor="#ffffff" :splitwidth="2" :fixsize="675" :minfixsize="200" ref="layoutright">
                  <template v-slot:fix>
                      <div style="height: 100%">
                          <vxe-table ref="reqtable" :data.sync="reqtabledata" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow resizable show-overflow size="mini" show-header-overflow :optimization="{ animat: false }" @current-change="reqchange_Event" header-align="center">
                              <vxe-table-column type="index" title="No." width="35" align="center"></vxe-table-column>
                              <vxe-table-column :field="items.field" :key="items.field" :title="items.title" :width="items.width" sortable v-for="items in reqtableColumn"></vxe-table-column>
                          </vxe-table>
                      </div>
                  </template>
                  <div style="height: 100%">
                      <vxe-table ref="reqdetailtable" :data.sync="reqdetailtabledata" :select-config="{ reserve: true }" :sort-config="{ trigger: 'cell' }" border height="auto" highlight-current-row highlight-hover-column highlight-hover-row how-header-overflow resizable show-overflow size="mini" show-header-overflow :optimization="{ animat: false }" header-align="center">
                          <vxe-table-column type="index" title="No." width="35" align="center"></vxe-table-column>
                          <vxe-table-column :field="items.field" :key="items.field" :title="items.title" :width="items.width" sortable v-for="items in reqdetailColumn"></vxe-table-column>
                      </vxe-table>
                  </div>
              </rm-layout-left>
          </div>
      </el-dialog>
  </div>
</template>

<script type="text/javascript">
import XEUtils from "xe-utils";
export default {
  name: "LIS622",
  data() {
      return {
          //筛选项目
          datetime1: "",
          datetime2: "",
          //统计项目
          deptnoflag: "0",
          wardnoflag: "0",
          specimenflag: "0",
          labdetpflag: "0",
          pattypeflag: "0",
          labgroupflag: "0",
          reqgroupflag: "0",
          reqitemflag: "0",
          rejectreasonflag: "0", //退回原因
          yearflag: "0",
          monthflag: "0",
          dayflag: "0",
          //查询条件
          ShowElse: false,
          wardno: "", //病区
          specimencode: "", //标本类型
          pattypecode: "", //病人类型
          reqdeptno: "", //科室
          workgroup: "", //标本类型组合
          labdeptcode: "", //检验科室
          labgroupid: "", //检验组别
          rptunitid: "", //报告单元
          rptunitidcomb: "", //报告单元组合
          reqgroupid: "", //分单类别
          txtperformdept: "", // 执行科室
          //表格属性
          tableheight: "auto",
          loading: false,
          //选项
          allreqstat: "0", //包含作废条码
          noundivide: "0", //剔除退回原因未分类
          nounusedreq: "0", //剔除无效申请单
          showrate: "0",
          //表格内容
          totalData: [],
          tableData: [],
          tableColumns: [],
          tableColumn: [],
          rejectColumn: [],
          currentindex: -1,
          //多选弹窗
          rptunitGroupOption: [],
          pattypeOption: [],
          reqgroupOption: [],
          rptunitOption: [],
          deptOption: [],
          labdeptOption: [],
          labgroupOption: [],
          wardOption: [],
          specOption: [],
          reqitemOption: [],
          multichktitle: "",
          dialogMultipleVisible: false,
          option1: [],
          option2: [],
          fieldname: "",
          selrow: [],
          dialogDetailVisible: false,
          reqtableColumn: [],
          reqdetailColumn: [],
          reqtabledata: [],
          reqdetailtabledata: [],

          colShow: "",
          datename: "签收日期",
          datecode: "sign",
          exportTableColLen: 0,
          exportUnqualifiedTableColLen: 0,
          performdeptname: "",
          rptunitcombname: "",
          querytype: "1",
          dlgDetailTitle: "",
      };
  },
  created() {
      this.QueryOption();
  },
  methods: {
      handleCommand(name) {
          this.datename = name;
          if (name == "签收日期") {
              this.datecode = "sign";
          } else {
              this.datecode = "return";
          }
      },
      QueryData() {
          this.loading = true;
          this.$tool
              .request({
                  url: "LIS/LIS6/LIS622",
                  method: "post",
                  data: {
                      action: "queryData",
                      recievedt1: this.datetime1,
                      recievedt2: this.datetime2,
                      wardno: this.wardno,
                      specimencode: this.specimencode,
                      pattype: this.pattypecode,
                      reqdeptno: this.reqdeptno,
                      specitemcomb: this.specitemcomb,
                      labdeptcode: this.labdeptcode,
                      labgroupid: this.labgroupid,
                      rptunitid: this.rptunitid,
                      reqgroupid: this.reqgroupid,
                      rptunitidcomb: this.rptunitidcomb,
                      allreqstat: this.allreqstat,
                      noundivide: this.noundivide,
                      nounusedreq: this.nounusedreq,
                      showrate: this.showrate,
                      performdept: this.txtperformdept,
                      deptnoflag: this.deptnoflag,
                      wardnoflag: this.wardnoflag,
                      specimenflag: this.specimenflag,
                      labdetpflag: this.labdetpflag,
                      reqitemflag: this.reqitemflag,
                      pattypeflag: this.pattypeflag,
                      labgroupflag: this.labgroupflag,
                      reqgroupflag: this.reqgroupflag,
                      rejectreasonflag: this.rejectreasonflag,
                      yearflag: this.yearflag,
                      monthflag: this.monthflag,
                      dayflag: this.dayflag,
                      datecode: this.datecode,
                      querytype: this.querytype,
                  },
              })
              .then((res) => {
                  this.loading = false;
                  this.tableColumns = res.RData.Cols;
                  this.tableData = res.RData.Data;
                  if (!!res.colShow) {
                      this.colShow = res.colShow;
                  }
              });
      },
      QueryOption() {
          this.$tool
              .request({
                  url: "LIS/LIS6/LIS622",
                  method: "post",
                  data: {
                      action: "initOption",
                  },
              })
              .then((res) => {
                  this.pattypeOption = res.pattypeOption;
                  this.deptOption = res.deptOption;
                  this.labdeptOption = res.labdeptOption;
                  this.rptunitOption = res.rptunitOption;
                  this.rptunitGroupOption = res.rptunitGroupOption;
                  this.wardOption = res.wardOption;
                  this.labgroupOption = res.labgroupOption;
                  this.reqgroupOption = res.reqgroupOption;
                  this.specOption = res.specOption;
                  this.reqitemOption = res.reqitemOption;
                  this.datetime1 = res.datetime + " 00:00:00";
                  this.datetime2 = res.datetime + " 23:59:59";
              });
      },
      footerMethod({ columns, data }) {
          return [
              columns.map((column, columnIndex) => {
                  if (columnIndex === 0) {
                      return "总计";
                  }
                  if (["cp_samplecount"].includes(column.property)) {
                      return this.SumAll(this.tableData, column.property);
                  }
                  if (["cp_rejectcount"].includes(column.property)) {
                      return this.SumAll(this.tableData, column.property);
                  }
                  if (["cp_recievecount"].includes(column.property)) {
                      return this.SumAll(this.tableData, column.property);
                  }
                  if (["cp_rejectrate"].includes(column.property)) {
                      if (this.tableData != null && this.tableData.length > 0) return Number((this.SumAll(this.tableData, "cp_rejectcount") / this.SumAll(this.tableData, "cp_samplecount")) * 100).toFixed(2) + "%";
                      else return "0%";
                  }
                  if (["cp_recieverate"].includes(column.property)) {
                      if (this.tableData != null && this.tableData.length > 0) return Number((this.SumAll(this.tableData, "cp_recievecount") / this.SumAll(this.tableData, "cp_samplecount")) * 100).toFixed(2) + "%";
                      else return "0%";
                  }
                  if (this.colShow.indexOf(column.property) != -1) {
                      if (column.property.indexOf("百分比") == -1) {
                          if (this.tableData != null && this.tableData.length > 0) {
                              return this.SumAll(this.tableData, column.property.toString());
                          } else return "";
                      } else {
                          if (this.tableData != null && this.tableData.length > 0) return Number((this.SumAll(this.tableData, column.property.replace("百分比", "")) / this.SumAll(this.tableData, "cp_samplecount")) * 100).toFixed(2) + "%";
                          else return "0%";
                      }
                  }

                  return null;
              }),
          ];
      },
      cellClassName({ row, rowIndex, $rowIndex, column, columnIndex, $columnIndex }) {
          if (!['req_deptno','req_wardno','specimen_code','labdeptcode','pat_typecode','labgroupid','req_groupid','req_itemcode','years','months','days','cp_samplecount','cp_rejectrate','cp_recievecount','cp_recieverate'].includes(column.property)){
              return "blueClick";
          }
      },
      footerCellClassName({ $rowIndex, column, columnIndex }) {},
      SumAll(data, property) {
          var plus = 0;
          if (data) {
              for (let i = 0, len = data.length; i < len; i++) {
                  plus += data[i][property] - 0;
              }
          }
          return plus;
      },
      popMultipleChk(e, fieldname, option, title) {
          let temp = XEUtils.clone(option, true);
          this.option1 = [];
          this.option2 = [];
          if (e != "") {
              let k = e.split(",");
              k.forEach((item) => {
                  let ndata = temp.find((m) => m.data == item);
                  if (ndata != undefined && ndata != null) {
                      this.option2.push(ndata);
                  }
              });
              temp.forEach((item) => {
                  if (k.indexOf(item.data + "") < 0) {
                      this.option1.push(item);
                  }
              });
          } else {
              this.option1 = temp;
          }
          this.fieldname = fieldname;
          this.multichktitle = title;
          this.dialogMultipleVisible = true;
      },
      closedialog(value, name) {
          if (value != "close") {
              this[name] = value;
          }
          this.dialogMultipleVisible = false;
      },
      performdeptChange(code, name) {
          this.txtperformdept = code;
          this.performdeptname = name;
      },
      rptunitcombChange(code, name) {
          this.rptunitidcomb = code;
          this.rptunitcombname = name;
      },
      ExportResult(){
          let data = this.getUnqualifiedExportData();
          let filtertxt = "统计条件：" + this.getExportFilter();
          var systemtime = XEUtils.toDateString(new Date(), "yyyy-MM-dd HH:mm:ss");
          let currowinfo = this.querytype == '1'? "退回原因" : "原因归类";
          this.$pub.exportTableExcelWithData(data, this.exportUnqualifiedTableColLen, "LIS622 标本签收合格率统计_"+systemtime+".xlsx", filtertxt, "统计类型：" + currowinfo);
      },
      getUnqualifiedExportData(){
          let datas = this.reqtabledata;
          var allcolumns = this.$refs.reqtable.getColumns();
          var tableColumn = [];
          for (let i = 0; i < allcolumns.length; i++) {
              tableColumn.push({
                  field: allcolumns[i].property,
                  title: allcolumns[i].title,
              });
          }
          this.exportUnqualifiedTableColLen = tableColumn.length;
          let columns = tableColumn.filter((item) => item.field);
          let headers = [columns.map((item) => item.title)];
          return headers.concat(
              datas.map((row) => {
                  return columns.map((column) => {
                      return row[column.field];
                  });
              })
          );
      },
      BtnExport() {
          let data = this.getExportData();
          let filtertxt = this.getExportFilter();
          this.$pub.exportTableExcelWithData(data, this.exportTableColLen, "LIS622 标本签收合格率统计.xlsx", filtertxt, "统计条件：");
      },
      // 获取当前导出文件的所有查询条件
      getExportFilter() {
          let filtertxt = this.datename + ":" + XEUtils.toDateString(this.datetime1, "yyyy-MM-dd") + "至" + XEUtils.toDateString(this.datetime2, "yyyy-MM-dd") + "; ";
          let tatcoltxt = "";
          if (this.deptnoflag == "1") tatcoltxt += "科室、";
          if (this.wardnoflag == "1") tatcoltxt += "病区、";
          if (this.specimenflag == "1") tatcoltxt += "样本类型、";
          if (this.labdetpflag == "1") tatcoltxt += "检验科室、";
          if (this.pattypeflag == "1") tatcoltxt += "病人类型、";
          if (this.labgroupflag == "1") tatcoltxt += "检验组别、";
          if (this.reqgroupflag == "1") tatcoltxt += "分单类别、";
          if (this.reqitemflag == "1") tatcoltxt += "申请项目、";
          if (this.yearflag == "1") tatcoltxt += "年、";
          if (this.monthflag == "1") tatcoltxt += "月、";
          if (this.dayflag == "1") tatcoltxt += "日、";
          if (tatcoltxt) filtertxt += "统计项目:" + tatcoltxt.substring(0, tatcoltxt.length - 1) + "; ";
          if (this.wardno) filtertxt += "病区:" + this.getOptionName(this.wardOption.filter((item) => ("," + this.wardno + ",").indexOf("," + item.data + ",") > -1)) + "; ";
          if (this.specimencode) filtertxt += "样本类型:" + this.getOptionName(this.specOption.filter((item) => ("," + this.specimencode + ",").indexOf("," + item.data + ",") > -1)) + "; ";
          if (this.pattypecode) filtertxt += "病人类型:" + this.getOptionName(this.pattypeOption.filter((item) => ("," + this.pattypecode + ",").indexOf("," + item.data + ",") > -1)) + "; ";
          if (this.reqdeptno) filtertxt += "科室:" + this.getOptionName(this.deptOption.filter((item) => ("," + this.reqdeptno + ",").indexOf("," + item.data + ",") > -1)) + "; ";
          if (this.txtperformdept) filtertxt += "执行科室:" + this.performdeptname + "; ";
          if (this.labdeptcode) filtertxt += "检验科室:" + this.getOptionName(this.labdeptOption.filter((item) => ("," + this.labdeptcode + ",").indexOf("," + item.data + ",") > -1)) + "; ";
          if (this.labgroupid) filtertxt += "检验组别:" + this.getOptionName(this.labgroupOption.filter((item) => ("," + this.labgroupid + ",").indexOf("," + item.data + ",") > -1)) + "; ";
          if (this.rptunitid) filtertxt += "报告单元:" + this.getOptionName(this.rptunitOption.filter((item) => ("," + this.rptunitid + ",").indexOf("," + item.data + ",") > -1)) + "; ";
          if (this.rptunitidcomb) filtertxt += "单元组合:" + this.rptunitcombname + "; ";
          if (this.reqgroupid) filtertxt += "分单类别:" + this.getOptionName(this.reqgroupOption.filter((item) => ("," + this.reqgroupid + ",").indexOf("," + item.data + ",") > -1)) + "; ";
          if (this.allreqstat == "1") filtertxt += "包含作废条码; ";
          if (this.noundivide == "1") filtertxt += "剔除退回原因未分类; ";
          if (this.nounusedreq == "1") filtertxt += "剔除无效申请单; ";
          if (this.showrate == "1") filtertxt += "显示百分比;";
          return filtertxt;
      },
      getOptionName(option) {
          if (option && option.length > 0) {
              let optionname = "";
              option.forEach((item) => {
                  if (item.hasOwnProperty("display")) {
                      optionname += item.display + ",";
                  } else {
                      optionname += item.label + ",";
                  }
              });
              return optionname.substring(0, optionname.length - 1);
          } else {
              return "";
          }
      },
      getExportData() {
          let datas = this.$refs.xTable1.afterFullData;
          let exportColumn = XEUtils.clone(this.tableColumns, true);
          this.exportTableColLen = exportColumn.length;
          let columns = exportColumn.filter((item) => item.field);
          let footerData = {};

          columns.forEach((item, index) => {
              if (index === 0) {
                  footerData[item.field] = "总计";
              }
              let resdata = this.tableData;

              if (["cp_samplecount"].includes(item.field)) {
                  footerData[item.field] = this.SumAll(this.tableData, item.field);
              }
              if (["cp_rejectcount"].includes(item.field)) {
                  footerData[item.field] = this.SumAll(this.tableData, item.field);
              }
              if (["cp_recievecount"].includes(item.field)) {
                  footerData[item.field] = this.SumAll(this.tableData, item.field);
              }
              if (["cp_rejectrate"].includes(item.field)) {
                  if (this.tableData.length > 0) {
                      footerData[item.field] = Number((this.SumAll(this.tableData, "cp_rejectcount") / this.SumAll(this.tableData, "cp_samplecount")) * 100).toFixed(2) + "%";
                  } else {
                      footerData[item.field] = "0%";
                  }
              }
              if (["cp_recieverate"].includes(item.field)) {
                  if (this.tableData.length > 0) {
                      footerData[item.field] = Number((this.SumAll(this.tableData, "cp_recievecount") / this.SumAll(this.tableData, "cp_samplecount")) * 100).toFixed(2) + "%";
                  } else {
                      footerData[item.field] = "0%";
                  }
              }
              if (this.colShow.indexOf(item.field) != -1) {
                  if (this.showrate == "1") {
                      if (this.colShow.indexOf(item.field + "百分比") != -1) {
                          footerData[item.field] = this.SumAll(this.tableData, item.field);
                      } else {
                          var a = item.field.replace("百分比", "");
                          footerData[item.field] = Number((this.SumAll(this.tableData, item.field.replace("百分比", "")) / this.SumAll(this.tableData, "cp_samplecount")) * 100).toFixed(2) + "%";
                      }
                  } else {
                      footerData[item.field] = this.SumAll(this.tableData, item.field);
                  }
              }
          });
          datas.splice(datas.length, 0, footerData);
          let headers = [columns.map((item) => item.title)];
          return headers.concat(
              datas.map((row) => {
                  return columns.map((column) => {
                      return this.retForamtVal(row[column.field], column.field);
                  });
              })
          );
      },
      toBuffer(wbout) {
          let buf = new ArrayBuffer(wbout.length);
          let view = new Uint8Array(buf);
          for (let index = 0; index !== wbout.length; ++index) view[index] = wbout.charCodeAt(index) & 0xff;
          return buf;
      },
      btn_openselEvent() {
          let mainheight = this.$refs.maindev.offsetHeight;
          this.ShowElse = !this.ShowElse;
          if (this.ShowElse) {
              this.$refs.topdev.style.height = "145px";
              this.$refs.centerdev.style.top = "150px";
              this.$refs.centerdev.style.height = mainheight - 150 + "px";
              this.tableheight = mainheight - 150;
          } else {
              this.$refs.topdev.style.height = "70px";
              this.$refs.centerdev.style.top = "75px";
              this.$refs.centerdev.style.height = mainheight - 75 + "px";
              this.tableheight = mainheight - 75;
          }
      },
      clearData() {
          this.tableData = [];
          this.tableColumns = [];
      },
      rCellDblClick({ row, column }) {
          this.selrow = row;
          if (['req_deptno','req_wardno','specimen_code','labdeptcode','pat_typecode','labgroupid','req_groupid','req_itemcode','years','months','days','cp_samplecount','cp_rejectrate','cp_recievecount','cp_recieverate'].includes(column.property)) {
              return false;
          }
          if (row[column.property] == "0") {
              this.$message.info("无不合格标本！");
              return false;
          }
          if(column.property == 'cp_rejectcount'){
              this.dlgDetailTitle ="不合格标本信息查看";
          }
          else{
              this.dlgDetailTitle =column.property + "信息查看";
          }
          this.$tool
              .request({
                  url: "LIS/LIS6/LIS622",
                  method: "post",
                  data: {
                      action: "queryDetail",
                      recievedt1: this.datetime1,
                      recievedt2: this.datetime2,
                      wardno: this.wardno,
                      specimencode: this.specimencode,
                      pattype: this.pattypecode,
                      reqdeptno: this.reqdeptno,
                      specitemcomb: this.specitemcomb,
                      labdeptcode: this.labdeptcode,
                      labgroupid: this.labgroupid,
                      rptunitid: this.rptunitid,
                      reqgroupid: this.reqgroupid,
                      rptunitidcomb: this.rptunitidcomb,
                      allreqstat: this.allreqstat,
                      noundivide: this.noundivide,
                      nounusedreq: this.nounusedreq,
                      showrate: this.showrate,
                      deptnoflag: this.deptnoflag,
                      wardnoflag: this.wardnoflag,
                      specimenflag: this.specimenflag,
                      labdetpflag: this.labdetpflag,
                      reqitemflag: this.reqitemflag,
                      pattypeflag: this.pattypeflag,
                      labgroupflag: this.labgroupflag,
                      reqgroupflag: this.reqgroupflag,
                      rejectreasonflag: this.rejectreasonflag,
                      reqitemflag: this.reqitemflag,
                      yearflag: this.yearflag,
                      monthflag: this.monthflag,
                      dayflag: this.dayflag,
                      selrow: this.selrow,
                      performdept: this.txtperformdept,
                      datecode: this.datecode,
                      colname: column.property,
                      querytype: this.querytype,
                  },
              })
              .then((res) => {
                  this.dialogDetailVisible = true;
                  this.reqtableColumn = res.RData.Cols;
                  this.reqtabledata = res.RData.Data;
                  this.$nextTick(() => {
                      this.$refs.reqtable.setCurrentRow(res.RData.Data[0]);
                      this.queryreqlog(res.RData.Data[0]);
                  });
              })
              .catch((e) => {});
      },
      reqchange_Event({ row, rowIndex, column, columnIndex }, event) {
          this.queryreqlog(row);
      },
      queryreqlog(row) {
          this.$tool
              .request({
                  url: "LIS/LIS6/LIS622",
                  method: "post",
                  data: {
                      action: "querylog",
                      barcode: row.barcode,
                  },
              })
              .then((res) => {
                  this.reqdetailColumn = res.RData.Cols;
                  this.reqdetailtabledata = res.RData.Data;
                  // this.$nextTick(() => {
                  //     this.$refs.rpttable.setCurrentRow(res.RData.Data[0]);
                  // });
              })
              .catch((e) => {});
      },

      formatFun({ cellValue, column, row }) {
          return this.retForamtVal(cellValue, column.property);
      },
      retForamtVal(cellValue, column) {
          if (column == "req_deptno") {
              try {
                  //科室
                  let deptname = this.deptOption.find((m) => m.data == cellValue);
                  if (deptname != undefined && deptname != null) {
                      return deptname.display;
                  } else {
                      return cellValue;
                  }
              } catch {
                  return cellValue;
              }
          } else if (column == "req_wardno") {
              try {
                  //病区
                  let wardname = this.wardOption.find((m) => m.data == cellValue);
                  if (wardname != undefined && wardname != null) {
                      return wardname.display;
                  } else {
                      return cellValue;
                  }
              } catch {
                  return cellValue;
              }
          } else if (column == "specimen_code") {
              try {
                  //样本类型
                  let specimenname = this.specOption.find((m) => m.data == cellValue);
                  if (specimenname != undefined && specimenname != null) {
                      return specimenname.display;
                  } else {
                      return cellValue;
                  }
              } catch {
                  return cellValue;
              }
          } else if (column == "labdeptcode") {
              try {
                  //检验科室
                  let deptname = this.labdeptOption.find((m) => m.data == cellValue);
                  if (deptname != undefined && deptname != null) {
                      return deptname.display;
                  } else {
                      return cellValue;
                  }
              } catch {
                  return cellValue;
              }
          } else if (column == "pat_typecode") {
              // 病人类型
              try {
                  let pattypename = this.pattypeOption.find((m) => m.data == cellValue);
                  if (pattypename != undefined && pattypename != null) {
                      return pattypename.display;
                  } else {
                      return cellValue;
                  }
              } catch {
                  return cellValue;
              }
          } else if (column == "labgroupid") {
              //检验工作组
              try {
                  let labgroup = this.labgroupOption.find((m) => m.data == cellValue);
                  if (labgroup != undefined && labgroup != null) {
                      return labgroup.display;
                  } else {
                      return "";
                  }
              } catch {
                  return "";
              }
          } else if (column == "req_groupid") {
              // 分单类别
              try {
                  let reqgroup = this.reqgroupOption.find((m) => m.data == cellValue);
                  if (reqgroup != undefined && reqgroup != null) {
                      return reqgroup.display;
                  } else {
                      return cellValue;
                  }
              } catch {
                  return cellValue;
              }
          } else if (column == "req_itemcode") {
              // 申请项目
              try {
                  let reqitem = this.reqitemOption.find((m) => m.data == cellValue);
                  if (reqitem != undefined && reqitem != null) {
                      return reqitem.display;
                  } else {
                      return cellValue;
                  }
              } catch {
                  return cellValue;
              }
          } else {
              return cellValue;
          }
      },
  },
};
</script>

<style scoped>
.pagetop {
  width: 100%;
  height: 70px;
  display: -webkit-box;
  -webkit-box-pack: left;
  -webkit-box-align: center;
  border: 1px solid #ccc;
  position: absolute;
  z-index: 99;
  white-space: nowrap;
  overflow-x: auto;
}

.pagecenter {
  position: absolute;
  top: 75px;
  width: 100%;
  left: 0;
  bottom: 0px;
  overflow: auto;
}

table tr td:nth-child(1) {
  width: 50px;
}

.left_nav {
  width: 20%;
  height: 100%;
  border-right: 1px solid #ccc;
  padding: 0px 0px 0px 0px;
  float: left;
  display: inline;
}

.left_nav div {
  cursor: pointer;
  height: 40px;
  width: 100%;
  float: left;
  padding-left: 20px;
  line-height: 40px;
}

.left_nav .active {
  background-color: DeepSkyBlue;
}

.right_nav {
  width: 80%;
  height: 100%;
  display: inline-block;
  vertical-align: top;
  float: left;
  display: inline;
}

::v-deep .blueClick {
  color: blue;
  cursor: pointer;
  user-select: none;
}

::v-deep .el-input--suffix .el-input__inner {
  padding-right: 10px;
}
::v-deep .el-checkbox {
  margin-right: 5px;
}
::v-deep .el-radio {
  text-align: left;
  margin-right: 10px;
}
</style>